<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
<canvas id="chart" width="800" height="400" style="background: #ccc;"></canvas>
<script>
  /** @type {HTMLCanvasElement} */ /* 添加canvs相关的语法提示 */
  // 得到画布
  const canvas = document.getElementById('chart')
  // 得到画笔
  const paint = canvas.getContext('2d')

  // 画线
  // paint.moveTo(100, 200)
  // paint.lineTo(200, 200)
  // paint.lineTo(150, 300)
  // paint.lineTo(100, 200)

  // 描边
  // paint.strokeStyle = 'red'
  // paint.stroke()
  // 填充
  paint.fillStyle = '#abc'
  paint.fill()

  // 绘制矩形
  paint.strokeStyle = 'red'
  paint.strokeRect(20, 50, 100, 50)
  
  paint.fillRect(20, 50, 100, 50)

  // 画圆
  paint.arc(300, 200, 50, 0, Math.PI*2)
  paint.fill()

  paint.moveTo(500, 100)
  paint.lineTo(400, 100)
  paint.lineTo(400, 200)
  paint.arc(400, 100, 100, 0, Math.PI/2, false)
  paint.fill()

  paint.beginPath() // 开始一个新的绘制
  paint.arc(200, 50, 50, 0, 2*Math.PI, false)
  paint.stroke()
  // paint.closePath()

  // 清除矩形区域
  paint.clearRect(0, 0, 100, 200)

  // 画文字
  paint.font = '30px 仿宋'
  // paint.textAlign = 'left'  // 左下角
  paint.textAlign = 'center' // 下中部
  paint.fillText('尚硅谷IT教育', 20, 30)

</script>
</body>
</html>